﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/OpenDelib.Master" CodeBehind="FicheEntreprise.aspx.vb" Inherits="OpenDelib.FicheEntreprise" %>
<%@ Register TagPrefix="asp" Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" %>
<%@ Register TagPrefix="cc1" Namespace="Odyssee.WebControles" Assembly="Odyssee.WebControles" %>
<%@ Register Src="~/Tiers/CtrlAdresse.ascx" TagPrefix="uc1" TagName="CtrlAdresse" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .gridview_jq_btn {
            vertical-align: middle;
        }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="toolbar" runat="server">   
    <hr/>
    <cc1:ToolBar ID="tbDossier" runat="server" CssClass="toolbar">
        <items>
            <cc1:ToolBarTextImageButton ID="btnActualiser" runat="server" Text="Actualiser" ImageWidth="20" ImageHorizontalOffset="4" ImageUrl="~/Images/refresh_white_20.png" />
            <cc1:ToolBarSeparator ID="tbSep1" runat="server" Offset="2" />
            <cc1:ToolBarTextImageButton ID="btnEnregister" runat="server" Text="Enregistrer" ImageWidth="20" ImageHorizontalOffset="4" ImageUrl="~/Images/save_white_20.png" />
        </items>
    </cc1:ToolBar> 
    <hr/>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="content" runat="server">
    <cc1:JQPopupPanel ID="pnlEntreprise" runat="server" PopupHeight="540" PopupWidth="700" Style="display: none;" Close="True" />

    <%--DIV ENTREPRISE--%>
    <div id="divEntreprise" class="bloc">
        <div class="divTitle">
            <asp:Label runat="server" Text="Entreprise" CssClass="labelDivTitle" />
        </div>

        <%--NOM--%>
        <div class="divMiniTitle">
            <asp:Label runat="server" Text="Nom" CssClass="label" />
        </div>
        <asp:TextBox ID="txtNom" runat="server" TextMode="SingleLine" CssClass="textbox upper" Style="width:calc(100% - 6px);" MaxLength="60" />
        
        <%--TYPE--%>
        <div class="divMiniTitle">
            <asp:Label runat="server" Text="Type" CssClass="label" />
        </div>
        <asp:DropDownList ID="cmbType" runat="server" CssClass="combo" Style="width: 100%; border: none;" />

        <%--ADRESSE--%>
        <uc1:CtrlAdresse runat="server" ID="CtrlAdresse" />
        
        <%--SIRET ET ABREGE--%>
        <div style="width:100%; display:flex;">
            <div class="divMiniTitle" style="width:50%; border-right: 1px solid black;">
                <asp:Label runat="server" Text="SIREN / SIRET" CssClass="label" />
            </div>
            <div class="divMiniTitle" style="width:50%; border-left: 1px solid black;">
                <asp:Label runat="server" Text="Abrégé" CssClass="label" />
            </div>
        </div>
        <div style="width:100%; display:flex;">
            <div style="width:50%; border-right: 1px solid black;">
                <asp:TextBox ID="txtSIRET" runat="server" CssClass="textbox" Style="width:calc(100% - 6px);" MaxLength="17" onblur="formatSiret()" />
            </div>
            <div style="width:50%; border-left: 1px solid black;">
                <asp:TextBox ID="txtAbrege" runat="server" CssClass="textbox" Style="width:calc(100% - 6px);" MaxLength="50" />
            </div>
        </div>

        <%--NUMEROS DE TELEPHONE ET DE FAX--%>
        <div style="width:100%; display:flex;">
            <div class="divMiniTitle" style="width:50%; border-right: 1px solid black;">
                <asp:Label runat="server" Text="Numéro de téléphone" CssClass="label" />
            </div>
            <div class="divMiniTitle" style="width:50%; border-left: 1px solid black;">
                <asp:Label runat="server" Text="Numéro de fax" CssClass="label" />
            </div>
        </div>
        <div style="width:100%; display:flex;">
            <div style="width:50%; border-right: 1px solid black;">
                <asp:TextBox ID="txtTelephone" runat="server" CssClass="textbox" Style="width:calc(100% - 6px);" MaxLength="14" />
            </div>
            <div style="width:50%; border-left: 1px solid black;">
                <asp:TextBox ID="txtFax" runat="server" CssClass="textbox" Style="width:calc(100% - 6px);" MaxLength="14" />
            </div>
        </div>

        <%--EMAIL--%>
        <div class="divMiniTitle">
            <asp:Label runat="server" Text="Adresse mail" CssClass="label" />
        </div>
        <asp:TextBox ID="txtEMail" runat="server" TextMode="SingleLine" CssClass="textbox" Style="width:calc(100% - 6px);" MaxLength="60" onblur="checkTextBoxEmail()" />

        <%--SITE WEB--%>
        <div class="divMiniTitle">
            <asp:Label runat="server" Text="Site web" CssClass="label" />
        </div>
        <asp:TextBox ID="txtSiteWeb" runat="server" TextMode="SingleLine" CssClass="textbox" Style="width:calc(100% - 6px);" MaxLength="100" />
    </div>

    <%--DIV CONTACTS--%>
    <div id="divContacts" runat="server" class="bloc">
        <div class="divTitle">
            <asp:Label runat="server" Text="Contacts" CssClass="labelDivTitle" />
        </div>
        <cc1:AcroGridView ID="gvContacts" runat="server" AutoGenerateColumns="false" CssClass="grid" AllowPaging="true" PageSize="10" PagerStyle-CssClass="gridpager" AllowSorting="false" EmptyDataText="Aucun contact" EmptyDataRowStyle-HorizontalAlign="Center" ShowHeaderWhenEmpty="True" style="border-bottom: 2px solid black; border-top: 2px solid black; height: 24px; line-height:24px; padding:0px;">
            <Columns>
                <cc1:BoundField DataField="CleContact" ReadOnly="True" SortExpression="CleContact" HeaderText="N°" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <cc1:BoundField DataField="Qualite" ReadOnly="True" SortExpression="Qualite" HeaderText="Qualité" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <cc1:BoundField DataField="Nom" ReadOnly="True" SortExpression="Nom" HeaderText="Nom" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <cc1:BoundField DataField="Prenom" ReadOnly="True" SortExpression="Prenom" HeaderText="Prénom" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <cc1:BoundField DataField="LibelleFonction" ReadOnly="True" SortExpression="LibelleFonction" HeaderText="Fonction" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <asp:TemplateField>
                    <ItemStyle HorizontalAlign="Right" />
                    <HeaderStyle HorizontalAlign="Right" />
                    <HeaderTemplate>
                        <cc1:JQPopupButton DoPostBack="true" Title="Sélectionner un contact" PopupHeight="660" PopupWidth="660" PopupUrl="~/Tiers/SelectionContacts.aspx" ID="btnAjouterContact" runat="server" CssClass="btn" Text="Ajouter" DisplayMode="TextImageButton" PopupPanelID="pnlEntreprise" URLParameters="&multiple=0" ImageWidth="20" ImageHorizontalOffset="4" ImageUrl="~/Images/plus_white_20.png" ClientIDMode="Static" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <cc1:JQPopupButton DoPostBack="true" Title="Modifier un lien entreprise / contact" PopupHeight="720" PopupWidth="600" PopupUrl="~/Tiers/LienEntrepriseContact.aspx" ID="btnLien" runat="server" Text="" DisplayMode="Image" PopupPanelID="pnlEntreprise" URLParameters='<%# "&cleContact=" & Eval("CleContact") & "&cleEntreprise=" & Server.UrlEncode(Me.CleEntite) & "&fonction=" & Server.UrlEncode(Eval("CodeFonction")) %>' ImageWidth="20" ImageHorizontalOffset="4" ImageUrl="~/Images/edit_link_20.png" ToolTip="Modifier lien" CssClass="gridview_jq_btn" />
                        &nbsp;
                        <asp:ImageButton ID="btnModifier" runat="server" AlternateText="Modifier" CommandArgument='<%#Eval("CleContact")%>' CommandName="Modifier" ImageUrl="~/Images/edit_20.png" ToolTip="Modifier" style="vertical-align:middle;" />
                        &nbsp;
                        <asp:ImageButton ID="btnSupprimer" runat="server" AlternateText="Supprimer" CommandArgument='<%#Eval("CleContact") & "¤" & Eval("CodeFonction")%>' CommandName="Supprimer" ImageUrl="~/Images/cancel_20.png" OnClientClick="return confirm('Êtes-vous sûr de vouloir enlever ce contact ?');" ToolTip="Supprimer" style="vertical-align:bottom;" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </cc1:AcroGridView>
    </div>

    <script type="text/javascript">
        function validateEmail(email) {
            var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            return re.test(email);
        }

        function checkTextBoxEmail()
        {
            var txtbox = document.getElementById('<%=txtEMail.ClientID%>');
            if (txtbox.value == '') return;
            if (validateEmail(txtbox.value) == false)
            {
                alert('Adresse mail invalide');         
            }
        }

        function formatSiret()
        {
            var txtbox = document.getElementById('<%=txtSIRET.ClientID%>');
            if (txtbox.value == '') return;

            var text = txtbox.value.replace(/ /g, '');
            if (text.length == 9)
            {
                txtbox.value = text.substring(0, 3) + ' ' + text.substring(3, 6) + ' ' + text.substring(6, 9);
            } else if (text.length == 14) {
                txtbox.value = text.substring(0, 3) + ' ' + text.substring(3, 6) + ' ' + text.substring(6, 9) + ' ' + text.substring(9, 14);
            }
        }

    </script>

</asp:Content>
